// 用户登录
var loginPage = (function(login) {
	var VUE = {};// Vue命名空间
	// var loginEntity = {};// 实体命名空间
	// loginEntity.loginFunction = function loginFunction() {
	// var loginDTO = {};
	// loginDTO.userName = LANTCommon.Str.Empty();
	// loginDTO.password = LANTCommon.Str.Empty();
	// loginDTO.vercode = LANTCommon.Str.Empty();
	// loginDTO.remember = LANTCommon.Str.Empty();
	// return loginDTO;
	// };
	VUE.InitPage = function Init() {
		var loginVm = new Vue({
			el : '#loginModel',
			data : {
				// loginDTO : loginEntity.loginFunction(),
				userName : LANTCommon.Str.Empty(),
				password : LANTCommon.Str.Empty(),
				vercode : LANTCommon.Str.Empty(),
				remember : LANTCommon.Str.Empty()
			},
			methods : {
				login : function() {
					if (!this.verifyUserName()) {
						layer.msg("请输入正确的用户名", {
							icon : 5
						});
						return;
					}

					if (!this.verifyPassword()) {
						layer.msg("请输入正确的密码", {
							icon : 5
						});
						return;
					}

					if (!this.checkVerify(this.vercode)) {
						return;
					}

					if ($('[name="remember"]').is(':checked')) {
						this.remember = 1;
					} else {
						this.remember = 0;
					}

					var userName = this.userName;
					var password = this.password;
					var remember = this.remember;
					$.ajax({
						async : false,
						type : 'post',
						url : '/lant/user/login',
						data : {
							userName : userName,
							password : password,
							remember : remember,
						},
						success : function(result) {
							if (LANTCommon.OK == result.status) {
								window.location.href = '/lant/page/index';
							} else {
								layer.msg(result.msg, {
									icon : 5
								});
							}
						}
					});
				},
				verifyUserName : function() {
					// 验证用户格式
					var pattern = /^[0-9a-zA-Z_@]{6,20}$/;
					return pattern.test(this.userName);
				},
				verifyPassword : function() {
					// 验证密码格式
					var pattern = /^[0-9a-zA-Z_@]{6,30}$/;
					return pattern.test(this.password);
				},
				rememberLogin : function() {
					//alert($('[name="remember"]').is(':checked'));
				},
				getVerify : function() {
					// 获取验证码
					$("#imgVerify").attr("src",
							'/lant/getVerify?' + Math.random());// jquery方式
				},
				checkVerify : function(vercode) {
					var flag = false;
					$.ajax({
						async : false,
						type : 'post',
						url : '/lant/checkVerify',
						data : {
							vercode : vercode
						},
						success : function(result) {
							if (LANTCommon.OK == result.status) {
								flag = true;
							} else {
								layer.msg(result.msg, {
									icon : 5
								});
							}
						}
					});

					this.getVerify();
					return flag;
				},
			}
		});
	};

	login.VUE = VUE;
	return login;
})(loginPage || {});
